[gnwrapper] Support KeyboardInterrupt on Google Colab

Gym-Notebook-Wrapper (aka. gnwrapper) is a Python package to render OpenAI Gym on Google Colaboratory (or Jupyter Notebook at Linux).

A class gnwrapper.Monitor wrapps gym.wrappers.Monitor and adds usuful features (e.g. starting virtual display automatically, showing videos on notebook).

Google Colaboratory allows users to stop a running cell by clicking a button. Internally, KeyboardInterrupt is emitted to stop program.

Unfortunately, this crashed notebook kernel with a following error message after running any cells interecting virtual display;

XIO: fatal IO error 0 (Success) on X server ":0"

This happens when Xvfb stops incorrectly (and as far as I know, we cannot stop Xvfb “correctly” with OpenAI Gym). I needed to prevent Xvfb termination.

After long struggling, I found a StackOverflow answer which allowed subprocess to ignore signals from parent process.

subprocess.Popen(...,preexcec_fn=os.setpgrp)

By hacking, subprocess for virtual display ignores parent signal. Now, gnwrapper version 1.2.4 can accept Google Colaboratory stop button.

Avatar
Hiroyuki Yamada

My research interests include machine learning, cloud native conputing.

Related